1
'***************************** Module Header ******************************\
2 '* Module Name: Travel.vb
3 '* Project: AzureBingMaps
4 '* Copyright (c) Microsoft Corporation.
6 '* Partial class for the Travel EF entity.
8 '* This source is subject to the Microsoft Public License.
9 '* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
10 '* All other rights reserved.
12 '* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
13 '* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
14 '* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
15 '\**************************************************************************
18 Imports System
.Data
.Objects
.DataClasses
19 Imports System
.Data
.Services
20 Imports System
.Data
.Services
.Common
22 Imports Microsoft
.SqlServer
.Types
25 ''' The partial class for the Travel EF entity.
26 ''' Both PartitionKey and RowKey are part of data service key.
27 ''' Properties such as EntityState and EntityKey should not be passed to the client.
28 ''' The binary representation GeoLocation does not need to be passed to the client as well.
30 <DataServiceKey(New String() {"PartitionKey", "RowKey"})> _
31 <IgnoreProperties(New String() {"EntityState", "EntityKey", "GeoLocation"})> _
32 Partial
Public Class Travel
34 Private _geoLocationText
As String
37 ''' The text representation of the geo location, which is more user friendly.
38 ''' When Latitude and Longitude are modified, GeoLocationText will be modified as well.
39 ''' Client may upload an entity with Latitude/Longitude, but without GeoLocationText, so its value could be null.
40 ''' To avoid unintentionally setting GeoLocaionText to null, let's check the value in setter.
42 Public Property GeoLocationText() As String
44 Return Me._geoLocationText
46 Set(ByVal value
As String)
47 If Not String.IsNullOrEmpty(value
) Then
48 Me._geoLocationText
= value
53 ' When either latitude or longitude changes, GeoLocationText must be changed as well.
54 ' The binary GeoLocation does not need to be changed, as it is only known by the database.
55 Private _latitude
As Double
56 Public Property Latitude() As Double
60 Set(ByVal value
As Double)
62 Me.GeoLocationText
= Me.LatLongToWKT(Me.Latitude
, Me.Longitude
)
66 Private _longitude
As Double
67 Public Property Longitude() As Double
71 Set(ByVal value
As Double)
73 Me.GeoLocationText
= Me.LatLongToWKT(Me.Latitude
, Me.Longitude
)
78 ''' Convert latitude and longitude to WKT.
80 Private Function LatLongToWKT(ByVal latitude
As Double, ByVal longitude
As Double) As String
81 Dim sqlGeography__1
As SqlGeography
= SqlGeography
.Point(latitude
, longitude
, 4326)
82 Return sqlGeography__1
.ToString()
86 ''' GeoLocationText, Latitude, Longitude do not correspond to any column in the database.
87 ''' Geolocation (binary) corresponds to the GeoLocation column in the TravelView.
88 ''' If the binary GeoLocation changes, those values should be modified as well.
89 ''' This could happen when querying the entity.
91 Private Sub OnGeoLocationChanging(ByVal value
As Global.System
.Byte())
92 If value IsNot
Nothing Then
93 Using ms
As New MemoryStream(value
)
94 Using reader
As New BinaryReader(ms
)
95 Dim sqlGeography
As New SqlGeography()
96 sqlGeography
.Read(reader
)
97 Me.GeoLocationText
= New String(sqlGeography
.STAsText().Value
)
98 Me.Latitude
= sqlGeography
.Lat
.Value
99 Me.Longitude
= sqlGeography
.[Long].Value